<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>创建账号</title>
<link rel="stylesheet" href="../static/layui/css/layui.css">
<style>    
  .layui-body{ padding: 10px}
</style>
</head>
<body>
    </br>
	<h2>创建账号</h2></br>
	<!-- 按钮区 -->
	<div class="site-demo-button" id="layerDemo" style="margin-bottom: 0;">
	  <button class="layui-btn">创建账号</button>
	  <button class="layui-btn">学生管理</button>
	  <button data-method="notice" class="layui-btn">导入学生</button>
	</div></br>
	
	<!-- 主体内容区 lay-verify="required"必填项  -->
	<form class="layui-form" action="student?m=add" method="post">
	  <!-- 用户名 -->
	  <div class="layui-form-item">
	    <label class="layui-form-label">用户名</label>
	    <div class="layui-input-block">
	      <input type="text" name="user" required  lay-verify="required" placeholder="用户名" autocomplete="off" class="layui-input">
	    </div>
	  </div>
	  
	  <!-- 权限 -->
	  <div class="layui-form-item">
	    <label class="layui-form-label">权限</label>
	    <div class="layui-input-block">
	      <select name="limit" lay-verify="required">
	        <option value="">权限选择</option>
	        <c:forEach items="${roleList}" var="cls">
	        <c:if test="${cls.role_name!=null}">
	        <option value="${cls.role_id}">${cls.role_name}</option>
	        </c:if>
	        </c:forEach>
	      </select>
        </div>
      </div>
	  
	  <!-- 班级 -->
	  <div class="layui-form-item">
	    <label class="layui-form-label">班级</label>
	    <div class="layui-input-block">
	      <select name="classes" lay-verify="required">
	        <option value="">班级选择</option>
	        <c:forEach items="${classlist}" var="cls">
	        <c:if test="${cls.class_name!=null}">
	        <option value="${cls.class_id}">${cls.class_name}</option>
	        </c:if>
	        </c:forEach>
	      </select>
        </div>
      </div>
	  
	  <!-- 密码 -->
	  <div class="layui-form-item">
	    <label class="layui-form-label">密码框</label>
	    <div class="layui-input-inline">
	      <input type="password" name="password" required lay-verify="required" placeholder="请输入密码" autocomplete="off" class="layui-input">
	    </div>
	    <div class="layui-form-mid layui-word-aux">密码不能为空</div>
	  </div>
	  
	  <!-- 性别 -->
	  <div class="layui-form-item">
	    <label class="layui-form-label">性别</label>
	    <div class="layui-input-block">
	      <input type="radio" name="sex" value="男" title="男">
	      <input type="radio" name="sex" value="女" title="女" checked>
	    </div>
	  </div>
	  
	  <!-- 电话 -->
	  <div class="layui-form-item">
	    <label class="layui-form-label">电话</label>
	    <div class="layui-input-block">
	      <input type="text" name="phone" placeholder="电话" autocomplete="off" class="layui-input">
	    </div>
	  </div>
	  
	  <!-- 微信 -->
	  <div class="layui-form-item">
	    <label class="layui-form-label">微信</label>
	    <div class="layui-input-block">
	      <input type="text" name="weixin" placeholder="微信" autocomplete="off" class="layui-input">
	    </div>
	  </div>
	  
	  <!-- 描述 -->
	  <div class="layui-form-item layui-form-text">
	    <label class="layui-form-label">描述</label>
	    <div class="layui-input-block">
	      <textarea name="desc" placeholder="请输入内容" class="layui-textarea"></textarea>
	    </div>
	  </div>
	  
	  <!-- 头像 -->
	  <div class="layui-form-item">
         <label class="layui-form-label">头像</label>
         <div class="layui-input-block">
             <input type="text" name="photo" id="test2" value="" style="display:none;"/>
             <button type="button" class="layui-btn" id="test1">
                 <i class="layui-icon"></i>上传图片
             </button>
         </div>
     </div>
	  
	  
	  <!-- 提交 -->
	  <div class="layui-form-item">
	    <div class="layui-input-block">
	      <button type="submit" class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
	      <button type="reset" class="layui-btn layui-btn-primary">重置</button>
	    </div>
	  </div>
</form>
 
</body>
<script type="text/javascript" src="../static/js/jquery.min.js"></script>
<script type="text/javascript" src="../static/layui/layui.js"></script>
<script>
//上传头像图片
layui.use('upload', function(){
  var upload = layui.upload;
   
  var uploadInst = upload.render({
	    elem: '#test1' //绑定元素
	    ,url: '../uploadImage' //上传接口
	    ,done: function(res){
	    	console.log(res);
            layui.$("#test2").attr('value', res.src);
            var v=$("#test2").attr('value');
            console.log(v);
            alert('上传成功');
	    }
	  });
});
//提交监听
layui.use('form', function(){
	  var form = layui.form;
	  
	  //监听提交
	  form.on('submit(formDemo)', function(){
	    layer.msg('注册成功，点击最后一页可查看');
	    return true;
	  });
});
//导出文件
layui.use('layer', function(){ //独立版的layer无需执行这一句
	  var $ = layui.jquery, layer = layui.layer; //独立版的layer无需执行这一句
	  
	  //触发事件
	  var active = {
	    notice: function(){
	      //示范一个公告层
	      layer.open({
	        type: 1
	        ,title: false //不显示标题栏
	        ,closeBtn: false
	        ,area: '500px;'
	        ,shade: 0.8
	        ,id: 'LAY_layuipro' //设定一个id，防止重复弹出
	        ,btn: ['下载模板', '关闭']
	        ,btnAlign: 'c'
	        ,moveType: 1 //拖拽模式，0或者1
	        ,content: '<div style="padding: 50px; line-height: 22px; background-color: #393D49; color: #fff; font-weight: 300;">'+
		        '导入学生<br><br>操作说明<br>'+
		        '1、下载 Excel格式模板 文件，并按照模板格式填写。<br>'+
	        	'2、导入前请仔细核对Excel数据的正确性。<br>'+
	        	'<br>批量导入<br>'+
	        	'<form action="../upload" method="post"  enctype="multipart/form-data">'+
   	                   '<input type="file" name="stufile" />'+
   	                   '<input type="submit" value="批量导入" />'+
   				'</form></div>'

	        ,success: function(layero){
	          var btn = layero.find('.layui-layer-btn');
	          btn.find('.layui-layer-btn0').attr({
	            href: 'http://localhost:8080/OnlineExam1/excel'
	            ,target: '_black'
	          });
	        }
	      });
	    }
	  };
	  
	  $('#layerDemo .layui-btn').on('click', function(){
	    var othis = $(this), method = othis.data('method');
	    active[method] ? active[method].call(this, othis) : '';
	  });
	  
});
//按钮切换
$(function(){
    $("button:eq(0)").click(function(){
    	window.location.href='http://localhost:8080/OnlineExam1/admin/student?m=addUser'
    });

    $("button:eq(1)").click(function(){
    	window.location.href='http://localhost:8080/OnlineExam1/admin/student_manage.jsp'
    }); 
});
</script>
</html>